(function() {
  $(function() {
    var $form, $wrap;
    $wrap = $(".search_wrap");
    $wrap.on("change", "select.category_id", function() {
      var category_id;
      category_id = $(this).val();
      if (parseInt(category_id) > 0) {
        return $.ajax({
          url: "/categories/" + category_id + "/childrens",
          dataType: 'json',
          success: function(data) {
            var item, options, _i, _len;
            options = "<option>请选择</option>";
            for (_i = 0, _len = data.length; _i < _len; _i++) {
              item = data[_i];
              options += "<option value='" + item.id + "'>" + item.cataname + "</option>";
            }
            $("select.children_id", $wrap).html(options);
            return $("select.children_id", $wrap).show();
          },
          error: function(xhr) {
            return console.error(xhr.responseText);
          }
        });
      } else {
        return $("select.children_id", $wrap).hide();
      }
    });
    $("input.begin_time", $wrap).datepicker({
      format: 'yyyy-mm-dd'
    });
    $("input.end_time", $wrap).datepicker({
      format: 'yyyy-mm-dd'
    });
    $form = $("form.research");
    return $form.on("click", ".submit", function() {
      if ($.trim($("input.keywords", $form).val()) !== "") {
        return $form.submit();
      }
    });

    /*
    $form = $("form.research")
    $('.search_btn').on 'click', ->
      $content = $('#searchContent')
      if $content.css('visibility')=='visible' && $.trim($("input", $content).val()) isnt ""
        $form.submit();
      else
        $content.css('visibility','visible');
     */
  });

}).call(this);
